<div class="row" style="padding-left: 50px; padding-right: 150px;">
  <div class="row flex-items-xs-between flex-items-xs-top" style="padding-left: 15px; padding-right: 15px;">
    <h3 class="header-title" id="创建计划任务模版">{{'CRONJOB.CREATE_TMP' | translate}}</h3>
  </div>
  <div style="position: fixed;right: 0;top: 100px; width: 200px; max-height: calc(100% - 160px); overflow-y: auto;">
    <wayne-navigation container=".content-area" [node]="naviList"></wayne-navigation>
  </div>
  <form #ngForm="ngForm" style="padding-right: 30px;width: 100%">
    <section class="form-block wrap">
      <div>
        <label class="label-level1" id="发布信息">{{'TMP.RELEASE_MESSAGE' | translate}}</label>
        <div class="form-group form-group-padding">
          <label class="col-md-3 form-group-label-override required">{{'TMP.RELEASE_EXPLAIN' | translate}}</label>
          <textarea name="description" [(ngModel)]="cronjobTpl.description" rows="3" style="width: 65%" required>
          </textarea>
        </div>
      </div>
    </section>
    <section class="form-block wrap">
      <div>
        <label class="label-level1" id="计划任务配置">{{'CRONJOB.CONFIG' | translate}}</label>
        <div style="padding-top:10px">
          <label class="col-md-12 form-group-label-override required">
            <span class="tooltip" style="color:red;" [innerHTML]="'CRONJOB.CONFIG_MESSAGE' | translate">
            </span>
          </label>
        </div>
        <div style="margin-top: 15px" class="form-group form-group-padding">
          <label class="col-md-3 form-group-label-override required">{{'CRONJOB.RUN_CYCLE' | translate}}
            <a role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg">
              <clr-icon shape="info-circle" size="24"></clr-icon>
              <span class="tooltip-content">{{'CRONJOB.RUN_CYCLE_MESSAGE' | translate}}</span>
            </a>
          </label>
          <label aria-haspopup="true" role="tooltip" [class.invalid]="!isScheduleValid"
                 class="tooltip tooltip-validation tooltip-md tooltip-bottom-left">
            <input type="text" name="schedule"
                   [(ngModel)]="kubeCronjob.spec.schedule"
                   size="40"
                   required
                   class="tooltip tooltip-validation tooltip-md tooltip-bottom-left"
                   [placeholder]="'CRONJOB.EXPRESSION' | translate">
            <span class="tooltip-content">
              {{'CRONJOB.EXPRESSION_MESSAGE' | translate}}
            </span>
            <a target="_blank" href="https://en.wikipedia.org/wiki/Cron">More</a>
          </label>
        </div>
        <div class="form-group form-group-padding">
          <label class="col-md-3 form-group-label-override required">{{'CRONJOB.PARALLEL_STRATEGY' | translate}}
            <a role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg">
              <clr-icon shape="info-circle" size="24"></clr-icon>
              <span class="tooltip-content">{{'CRONJOB.PARALLEL_STRATEGY_MESSAGE' | translate}}</span>
            </a>
          </label>
          <label aria-haspopup="true" role="tooltip" class="tooltip tooltip-validation tooltip-md tooltip-bottom-left">
            <div class="select">
              <select name="concurrencyPolicy" [(ngModel)]="kubeCronjob.spec.concurrencyPolicy">
                <option value="Allow" selected>{{'ACTION.ALLOW' | translate}}</option>
                <option value="Forbid">{{'ACTION.FORBID' | translate}}</option>
                <option value="Replace">{{'ACTION.REPLACE' | translate}}</option>
              </select>
            </div>
          </label>
        </div>
        <div class="form-group form-group-padding">
          <label class="col-md-3 form-group-label-override required">{{'CRONJOB.MAX_EXECUTE_TIME' | translate}}
            <a role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg">
              <clr-icon shape="info-circle" size="24"></clr-icon>
              <span class="tooltip-content">{{'CRONJOB.MAX_EXECUTE_TIME_MESSAGE' | translate}}</span>
            </a>
          </label>
          <label aria-haspopup="true" role="tooltip" [class.invalid]="formValid('activeDeadlineSeconds')"
                 class="tooltip tooltip-validation tooltip-md tooltip-bottom-left">
            <input type="number" name="activeDeadlineSeconds"
                   [(ngModel)]="kubeCronjob.spec.jobTemplate.spec.activeDeadlineSeconds" size="45" required
                   [placeholder]="'CRONJOB.MAX_EXECUTE_TIME' | translate">{{'UNIT.SECOND' | translate}}
          </label>
        </div>
        <!--
        <div class="form-group form-group-padding">
          <label class="col-md-3 form-group-label-override required">最大成功历史
            <a role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg">
              <clr-icon shape="info-circle" size="24"></clr-icon>
              <span class="tooltip-content">最大保留成功记录的数量。</span>
            </a>
          </label>
          <label aria-haspopup="true" role="tooltip" [class.invalid]="formValid('successfulJobsHistoryLimit')" class="tooltip tooltip-validation tooltip-md tooltip-bottom-left">
            <input type="number" name="successfulJobsHistoryLimit" [(ngModel)]="kubeCronjob.spec.successfulJobsHistoryLimit" size="45" required
                   placeholder="'CRONJOB.MAX_EXECUTE_TIME' | translate">
          </label>
        </div>
        <div class="form-group form-group-padding">
          <label class="col-md-3 form-group-label-override required">最大失败历史
            <a role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg">
              <clr-icon shape="info-circle" size="24"></clr-icon>
              <span class="tooltip-content">最大保留失败记录的数量</span>
            </a>
          </label>
          <label aria-haspopup="true" role="tooltip" [class.invalid]="formValid('failedJobsHistoryLimit')" class="tooltip tooltip-validation tooltip-md tooltip-bottom-left">
            <input type="number" name="failedJobsHistoryLimit" [(ngModel)]="kubeCronjob.spec.failedJobsHistoryLimit" size="45" required
                   placeholder="'CRONJOB.MAX_EXECUTE_TIME' | translate">
          </label>
        </div>-->
      </div>
    </section>
    <section *ngFor="let container of kubeCronjob.spec.jobTemplate.spec.template.spec.containers; let i = index"
             class="form-block wrap">
      <div>
        <label class="label-level1" [id]="i ? '容器配置' + i : '容器配置'">{{'TMP.CONTAINER_CONFIG' | translate}}
          <clr-icon (click)="onDeleteContainer(i)" shape="trash" title="删除容器" class="is-solid"></clr-icon>
        </label>
        <div class="container-box">
          <label class="label-level2" [id]="i ? '镜像配置' + i : '镜像配置'">{{'TMP.IMAGE_CONFIG' | translate}}</label>
          <div class="form-group form-group-padding">
            <label class="col-md-3 form-group-label-override required">{{'TMP.CONTAINER_NAME' | translate}}</label>
            <label aria-haspopup="true" role="tooltip" [class.invalid]="containerIsInvalid(i,'container.name_')"
                   class="tooltip tooltip-validation tooltip-md tooltip-bottom-left">
              <input type="text" size="90" class="col-sm-12" required name="container.name_{{i}}"
                     pattern="[a-z]([-a-z0-9]*[a-z0-9])?" [(ngModel)]="container.name"
                     [placeholder]="'RULE.CONTAINER' | translate">
              <span class="tooltip-content">
                {{'RULE.REGEXT' | translate}}[a-z]([-a-z0-9]*[a-z0-9])?
              </span>
            </label>
          </div>
          <div class="form-group form-group-padding">
            <label class="col-md-3 form-group-label-override required">{{'TMP.IMAGE_ADDRESS' | translate}}</label>
            <label aria-haspopup="true" role="tooltip" [class.invalid]="containerIsInvalid(i,'container.image_')"
                   class="tooltip tooltip-validation tooltip-md tooltip-bottom-left">
              <input type="text" size="90" class="col-sm-12" name="container.image_{{i}}" required
                     pattern="{{getImagePrefixReg()}}" [(ngModel)]="container.image"
                     [placeholder]="'TMP.IMAGE_ADDRESS' | translate">
              <span class="tooltip-content">
                {{'RULE.REGEXT' | translate}} {{getImagePrefixReg()}}
              </span>
            </label>
          </div>
          <div class="form-group form-group-padding">
            <label class="col-md-3 form-group-label-override required">{{'TMP.MEMORY_NUM' | translate}}</label>
            <label aria-haspopup="true" [class.invalid]="!checkMemory(container.resources.limits.memory)"
                   style="padding-right: 0;margin-right: 0;padding-left: 0"
                   role="tooltip" class="col-md-6 tooltip tooltip-validation tooltip-md tooltip-bottom-left">
              <input type="number" style="width:inherit" name="container.resources.limits.memory_{{i}}" required
                     [(ngModel)]="container.resources.limits.memory"
                     [placeholder]="'UNIT.MEMORY' | translate">
              <span [translate]="'RULE.MEMORY'" [translateParams]="{value: memoryLimit}" class="tooltip-content">
              </span>
            </label>
            <label class="col-md-3">G&nbsp;&nbsp;&nbsp;
            </label>
          </div>
          <div class="form-group form-group-padding">
            <label class="col-md-3 form-group-label-override required">{{'TMP.CORE_NUM' | translate}}</label>
            <label aria-haspopup="true" [class.invalid]="!checkCpu(container.resources.limits.cpu)"
                   style="padding-right: 0;margin-right: 0;padding-left: 0"
                   role="tooltip" class="col-md-6 tooltip tooltip-validation tooltip-md tooltip-bottom-left">
              <input type="number" name="container.resources.limits.cpu_{{i}}"
                     [(ngModel)]="container.resources.limits.cpu" style="width:inherit"
                     required [placeholder]="'UNIT.CPU' | translate">
              <span [translate]="'RULE.CPU' | translate" [translateParams]="{value: cpuLimit}" class="tooltip-content">
              </span>
            </label>
            <label class="col-md-3">{{'UNIT.CORE' | translate}}&nbsp;&nbsp;&nbsp;
            </label>
          </div>

        </div>

        <div class="container-box">
          <label class="label-level2" [id]="i ? '环境变量配置' + i : '环境变量配置'">{{'TMP.ENVIRONMENT_VAR' | translate}}
            <button (click)="onAddEnvFrom(i)" style="margin-left: 10px;" class="wayne-button primary">
              <clr-icon shape="add-text"></clr-icon>
              {{'TMP.ADD_GROUP' | translate}}</button>
            <button (click)="onAddEnv(i)" style="margin-left: 10px;" class="wayne-button primary">
              <clr-icon shape="add"></clr-icon>
              {{'TMP.ADD_ONE' | translate}}</button>
          </label>
          <div *ngFor="let envFrom of container.envFrom; let j = index">
            <div class="form-group form-group-padding">
              <label for="envFromType-{{i}}-{{j}}"
                     class="col-md-3 form-group-label-override required">{{'TMP.ADD_GROUP' | translate}}
                <a role="tooltip" aria-haspopup="true" class="tooltip tooltip-md">
                  <clr-icon shape="info-circle" size="24"></clr-icon>
                  <span class="tooltip-content">{{'TMP.LOAD_GROUP_MESSAGE' | translate}}</span>
                </a>
              </label>
              <div class="select">
                <select id="envFromType-{{i}}-{{j}}" name="envFrom.type_{{i}}_{{j}}"
                        (change)="envFromChange($event.target.value,i,j)">
                  <option value="1" [selected]="envFrom.configMapRef">{{'TMP.LOAD_CONFIGMAP' | translate}}</option>
                  <option value="2" [selected]="envFrom.secretRef">{{'TMP.LOAD_SECRET' | translate}}</option>
                </select>
              </div>

              <clr-icon style="margin-top: 10px;margin-right: 8px" (click)="onAddEnvFrom(i)" shape="plus-circle"
                        [title]="'TMP.ADD_ENVIRONMENT' | translate" class="is-solid"></clr-icon>
              <clr-icon style="margin-top: 10px" (click)="onDeleteEnvFrom(i,j)" shape="trash"
                        [title]="'TMP.DELETE_ENVIRONMENT' | translate" class="is-solid"></clr-icon>
            </div>
            <div *ngIf="envFrom" class="form-group form-group-padding">
              <input type="text" size="40" name="envFrom.prefix_{{i}}_{{j}}" [(ngModel)]="envFrom.prefix"
                     [placeholder]="'PLACEHOLDER.ENVIRONMENT' | translate">
            </div>
            <div *ngIf="envFrom && envFrom.configMapRef" class="form-group form-group-padding">
              <input type="text" size="40" required name="envFrom.configMapRef.name_{{i}}_{{j}}"
                     [(ngModel)]="envFrom.configMapRef.name"
                     [placeholder]="'TMP.CONFIGMAP_NAME' | translate">
            </div>
            <div *ngIf="envFrom && envFrom.secretRef" class="form-group form-group-padding">
              <input type="text" size="40" required name="envFrom.secretRef.name_{{i}}_{{j}}"
                     [(ngModel)]="envFrom.secretRef.name" [placeholder]="'TMP.SECRET_NAME' | translate">
            </div>

          </div>

          <div *ngFor="let env of container.env; let j = index">
            <div class="form-group form-group-padding">
              <label for="envType-{{i}}-{{j}}"
                     class="col-md-3 form-group-label-override required">{{'TMP.ADD_ONE' | translate}}
                <a role="tooltip" aria-haspopup="true" class="tooltip tooltip-md">
                  <clr-icon shape="info-circle" size="24"></clr-icon>
                  <span class="tooltip-content">{{'TMP.SUPPORT_ENVIRONMENT_MESSAGE' | translate}}</span>
                </a>
              </label>
              <div class="select">
                <select id="envType-{{i}}-{{j}}" name="env.type_{{i}}_{{j}}"
                        (change)="envChange($event.target.value,i,j)">
                  <option value="0" [selected]="env.value!=null">{{'TMP.LOAD_ENVIRONMENT' | translate}}</option>
                  <option value="1"
                          [selected]="env.valueFrom?.configMapKeyRef">{{'TMP.LOAD_CONFIGMAP' | translate}}</option>
                  <option value="2" [selected]="env.valueFrom?.secretKeyRef">{{'TMP.LOAD_SECRET' | translate}}</option>
                  <option value="3" selected>{{'OTHER' | translate}}</option>
                </select>
              </div>
              <clr-icon style="margin-top: 10px;margin-right: 8px" (click)="onAddEnv(i)" shape="plus-circle"
                        [title]="'TMP.ADD_ENVIRONMENT' | translate" class="is-solid"></clr-icon>
              <clr-icon style="margin-top: 10px" (click)="onDeleteEnv(i,j)" shape="trash"
                        [title]="'TMP.DELETE_ENVIRONMENT' | translate" class="is-solid"></clr-icon>
            </div>
            <div class="form-group form-group-padding">
              <input [(ngModel)]="env.name" required name="env.name_{{i}}_{{j}}" type="text" size="45"
                     [placeholder]="'TMP.ENVIRONMENT_NAME' | translate">
            </div>
            <div *ngIf="env.value != null" class="form-group form-group-padding">
              <input [(ngModel)]="env.value" required name="env.value_{{i}}_{{j}}" type="text" size="45"
                     [placeholder]="'TMP.ENVIRONMENT_VAR' | translate">
            </div>
            <div *ngIf="env.valueFrom && env.valueFrom.configMapKeyRef" class="form-group form-group-padding">
              <input type="text" size="40" required name="env.valueFrom.configMapKeyRef.name_{{i}}_{{j}}"
                     [(ngModel)]="env.valueFrom.configMapKeyRef.name"
                     [placeholder]="'TMP.CONFIGMAP_NAME' | translate">
              <input type="text" size="40" required name="env.valueFrom.configMapKeyRef.key_{{i}}_{{j}}"
                     [(ngModel)]="env.valueFrom.configMapKeyRef.key"
                     [placeholder]="'TMP.CONFIGMAP_KEY' | translate">
            </div>
            <div *ngIf="env.valueFrom && env.valueFrom.secretKeyRef" class="form-group form-group-padding">
              <input type="text" size="40" required name="env.valueFrom.secretKeyRef.name_{{i}}_{{j}}"
                     [(ngModel)]="env.valueFrom.secretKeyRef.name"
                     [placeholder]="'TMP.SECRET_NAME' | translate">
              <input type="text" size="40" required name="env.valueFrom.secretKeyRef.key_{{i}}_{{j}}"
                     [(ngModel)]="env.valueFrom.secretKeyRef.key"
                     [placeholder]="'TMP.SECRET_KEY' | translate">
            </div>

          </div>

        </div>

      </div>
    </section>
  </form>
</div>
<div class="clr-wizard-footer-buttons tpl-bottom" [style.top.px]="top">
  <button type="button" class="btn btn-outline" (click)="onCancel()">{{'BUTTON.CANCEL' | translate}}</button>
  <button type="button" class="btn btn-primary"
          (click)="onAddContainer()">{{'BUTTON.ADD_CONTAINER' | translate}}</button>
  <button type="button" class="btn btn-primary" (click)="openModal()">{{'BUTTON.ADVANCED_CONFIG' | translate}}</button>
  <button type="button" class="btn btn-primary" [disabled]="!isValid"
          (click)="onSubmit()">{{'BUTTON.SUBMIT' | translate}}</button>
</div>

<wayne-ace-editor (outputObj)="saveCronjob($event)"></wayne-ace-editor>
